#!/bin/bash

# IP HOST A
IP_A="10.55.6.50"
BROADCAST_A="10.55.6.255"
MASCARA_A="255.255.255.0"

# IP HOST B
IP_B="10.55.7.101"
BROADCAST_B="10.55.7.127"
MASCARA_B="255.255.255.128"

# IP HOST C
IP_C="10.4.203.210"
BROADCAST_C="10.4.203.223"
MASCARA_C="255.255.255.224"

# DIRECCIONES DE RED
atom="10.4.203.64"
benji="10.55.6.0"
callahan="192.168.15.0"
dtfrank="10.4.203.96"
eddie="10.31.101.0"
oliver="10.4.203.128"
fleming="172.17.1.64"
gamou="10.55.7.144"
hyuga="10.55.7.0"
ichiro="10.55.7.148"
johnson="10.4.203.192"
koriotto="10.4.203.0"
leblanc="10.55.7.128"
misaki="10.6.1.0"
napoleon="10.4.203.224"

# GATEWAYS HOST A
G_A_atom="10.55.6.4" #VRRP R4-R5
G_A_benji="10.55.6.4" #VRRP R4-R5
G_A_callahan="10.55.6.4" #VRRP R4-R5
G_A_dtfrank="10.55.6.4" #VRRP R4-R5
G_A_eddie="10.55.6.4" #VRRP R4-R5
G_A_oliver="10.55.6.4" #VRRP R4-R5
G_A_fleming="10.55.6.4" #VRRP R4-R5
G_A_gamou="10.55.6.4" #VRRP R4-R5
G_A_hyuga="10.55.6.4" #VRRP R4-R5
G_A_ichiro="10.55.6.4" #VRRP R4-R5
G_A_johnson="10.55.6.4" #VRRP R4-R5
G_A_koriotto="10.55.6.4" #VRRP R4-R5
G_A_leblanc="10.55.6.4" #VRRP R4-R5
G_A_misaki="10.55.6.4" #VRRP R4-R5
G_A_napoleon="10.55.6.4" #VRRP R4-R5

# GATEWAYS HOST B
G_B_atom="10.55.7.3" #R10
G_B_benji="10.55.7.3" #R10
G_B_callahan="10.55.7.3" #R10
G_B_dtfrank="10.55.7.3" #R10
G_B_eddie="10.55.7.3" #R10
G_B_oliver="10.55.7.3" #R10
G_B_fleming="10.55.7.3" #R10
G_B_gamou="10.55.7.3" #R10
G_B_hyuga="10.55.7.3" #R10
G_B_ichiro="10.55.7.3" #R10
G_B_johnson="10.55.7.3" #R10
G_B_koriotto="10.55.7.3" #R10
G_B_leblanc="10.55.7.3" #R10
G_B_misaki="10.55.7.3" #R10
G_B_napoleon="10.55.7.3" #R10

# GATEWAYS HOST C
G_C_atom="10.4.203.194" #R14
G_C_benji="10.4.203.194" #R14
G_C_callahan="10.4.203.194" #R14
G_C_dtfrank="10.4.203.194" #R14
G_C_eddie="10.4.203.194" #R14
G_C_oliver="10.4.203.194" #R14
G_C_fleming="10.4.203.194" #R14
G_C_gamou="10.4.203.194" #R14
G_C_hyuga="10.4.203.194" #R14
G_C_ichiro="10.4.203.194" #R14
G_C_johnson="10.4.203.194" #R14
G_C_koriotto="10.4.203.194" #R14
G_C_leblanc="10.4.203.194" #R14
G_C_misaki="10.4.203.194" #R14
G_C_napoleon="10.4.203.194" #R14

# MASCARAS DE RED
M_atom="255.255.255.224"
M_benji="255.255.255.0"
M_callahan="255.255.255.0"
M_dtfrank="255.255.255.224"
M_eddie="255.255.255.0"
M_oliver="255.255.255.224"
M_fleming="255.255.255.192"
M_gamou="255.255.255.252"
M_hyuga="255.255.255.128"
M_ichiro="255.255.255.252"
M_johnson="255.255.255.224"
M_koriotto="255.255.255.192"
M_leblanc="255.255.255.240"
M_misaki="255.255.255.0"
M_napoleon="255.255.255.224"

function hostA(){

	#CONFIGURACION INTERFACES
	ifconfig $interfaz $IP_A broadcast $BROADCAST_A netmask $MASCARA_A

	#Ruteo Estatico
	route add -net $atom netmask $M_atom gw $G_A_atom dev $interfaz
	#route add -net $benji netmask $M_benji gw $G_A_benji dev $interfaz
	route add -net $callahan netmask $M_callahan gw $G_A_callahan dev $interfaz
	route add -net $dtfrank netmask $M_dtfrank gw $G_A_dtfrank dev $interfaz
	route add -net $eddie netmask $M_eddie gw $G_A_eddie dev $interfaz
	route add -net $oliver netmask $M_oliver gw $G_A_oliver dev $interfaz
	route add -net $fleming netmask $M_fleming gw $G_A_fleming dev $interfaz
	route add -net $gamou netmask $M_gamou gw $G_A_gamou dev $interfaz
	route add -net $hyuga netmask $M_hyuga gw $G_A_hyuga dev $interfaz
	route add -net $ichiro netmask $M_ichiro gw $G_A_ichiro dev $interfaz
	route add -net $johnson netmask $M_johnson gw $G_A_johnson dev $interfaz
	route add -net $koriotto netmask $M_koriotto gw $G_A_koriotto dev $interfaz
	route add -net $leblanc netmask $M_leblanc gw $G_A_leblanc dev $interfaz
	route add -net $misaki netmask $M_misaki gw $G_A_misaki dev $interfaz
	route add -net $napoleon netmask $M_napoleon gw $G_A_napoleon dev $interfaz

	#Configuracion DNS	
	cd ../DNS/
	chmod +x *
	./dns.sh host resto	
}


function hostB(){
	
	#CONFIGURACION INTERFACES
	ifconfig $interfaz $IP_B broadcast $BROADCAST_B netmask $MASCARA_B

	#RUTEO ESTATICO
	route add -net $atom netmask $M_atom gw $G_B_atom dev $interfaz
	route add -net $benji netmask $M_benji gw $G_B_benji dev $interfaz
	route add -net $callahan netmask $M_callahan gw $G_B_callahan dev $interfaz
	route add -net $dtfrank netmask $M_dtfrank gw $G_B_dtfrank dev $interfaz
	route add -net $eddie netmask $M_eddie gw $G_B_eddie dev $interfaz
	route add -net $oliver netmask $M_oliver gw $G_B_oliver dev $interfaz
	route add -net $fleming netmask $M_fleming gw $G_B_fleming dev $interfaz
	route add -net $gamou netmask $M_gamou gw $G_B_gamou dev $interfaz
	#route add -net $hyuga netmask $M_hyuga gw $G_B_hyuga dev $interfaz
	route add -net $ichiro netmask $M_ichiro gw $G_B_ichiro dev $interfaz
	route add -net $johnson netmask $M_johnson gw $G_B_johnson dev $interfaz
	route add -net $koriotto netmask $M_koriotto gw $G_B_koriotto dev $interfaz
	route add -net $leblanc netmask $M_leblanc gw $G_B_leblanc dev $interfaz
	route add -net $misaki netmask $M_misaki gw $G_B_misaki dev $interfaz
	route add -net $napoleon netmask $M_napoleon gw $G_B_napoleon dev $interfaz

	#Configuracion DNS
	cd ../DNS/
	chmod +x *
	./dns.sh host resto	
}

function hostC(){
	ifconfig $interfaz $IP_C broadcast $BROADCAST_C netmask $MASCARA_C

	route add -net $atom netmask $M_atom gw $G_C_atom dev $interfaz
	route add -net $benji netmask $M_benji gw $G_C_benji dev $interfaz
	route add -net $callahan netmask $M_callahan gw $G_C_callahan dev $interfaz
	route add -net $dtfrank netmask $M_dtfrank gw $G_C_dtfrank dev $interfaz
	route add -net $eddie netmask $M_eddie gw $G_C_eddie dev $interfaz
	route add -net $oliver netmask $M_oliver gw $G_C_oliver dev $interfaz
	route add -net $fleming netmask $M_fleming gw $G_C_fleming dev $interfaz
	route add -net $gamou netmask $M_gamou gw $G_C_gamou dev $interfaz
	route add -net $hyuga netmask $M_hyuga gw $G_C_hyuga dev $interfaz
	route add -net $ichiro netmask $M_ichiro gw $G_C_ichiro dev $interfaz
	#route add -net $johnson netmask $M_johnson gw $G_C_johnson dev $interfaz
	route add -net $koriotto netmask $M_koriotto gw $G_C_koriotto dev $interfaz
	route add -net $leblanc netmask $M_leblanc gw $G_C_leblanc dev $interfaz
	route add -net $misaki netmask $M_misaki gw $G_C_misaki dev $interfaz
	route add -net $napoleon netmask $M_napoleon gw $G_C_napoleon dev $interfaz

	#Configuracion DNS
	cd ../DNS/
	chmod +x *
	./dns.sh host resto	
}

#****************************************************#
#******************SETUP GENERAL*********************#
#****************************************************#
#Reinicia interfases
./setUp_Interfases.sh
#Obtiene el nombre de la interfaz de la pc
interfaz=`ifconfig | egrep "eth" | sed 's/^\([A-Za-z0-9:]*\).*/\1/'`
#****************************************************#

case $1 in
A) hostA;;
B) hostB;;
C) hostC;;
*) echo "Parametros incorrectos. Uso: hosts [tipo] siendo tipo={A,B,C}"
esac 









